
# 熵阈值敏感性数据
lambda_M = [0.5, 0.6, 0.7, 0.8, 0.9]
accuracy = [75.3, 78.2, 80.1, 76.8, 73.5]  # 精度 (%)
comm_cost = [7.2, 5.4, 4.1, 6.3, 8.7]      # 通信成本 (MB/轮)

# 创建双Y轴图
fig, ax1 = plt.subplots(figsize=(5, 3))
ax1.plot(lambda_M, accuracy, 'bo-', linewidth=2, label='Accuracy')
ax1.set_xlabel(r'Entropy Threshold $\lambda_M$', fontsize=12)
ax1.set_ylabel('Accuracy (%)', color='b', fontsize=12)
ax1.tick_params(axis='y', labelcolor='b')
ax1.set_ylim(70, 85)

ax2 = ax1.twinx()
ax2.plot(lambda_M, comm_cost, 'rs--', linewidth=2, label='Communication Cost')
ax2.set_ylabel('Communication Cost (MB/round)', color='r', fontsize=12)
ax2.tick_params(axis='y', labelcolor='r')
ax2.set_ylim(3, 10)

# 标注最优区间
ax1.axvspan(0.65, 0.75, alpha=0.2, color='green')
# ax1.text(0.7, 76, 'Optimal Range\n(λ_M=0.6-0.7)', 
#          ha='center', fontsize=10, bbox=dict(facecolor='white', alpha=0.8))

# 标注关键点
# ax1.annotate('精度峰值: 80.1%', xy=(0.7,80.1), xytext=(0.65,82),
#              arrowprops=dict(arrowstyle='->'), fontsize=10)
# ax2.annotate('通信最低点: 4.1MB', xy=(0.7,4.1), xytext=(0.75,3.5),
#              arrowprops=dict(arrowstyle='->'), fontsize=10)

# plt.title(r'Impact of Entropy Threshold $\lambda_M$ on Accuracy and Communication', fontsize=14)
fig.legend(loc='upper left', bbox_to_anchor=(0.15, 0.85))
plt.savefig('entropy_threshold_impact_en.png', bbox_inches='tight')
